package xinyou.jh.net
{
	import flash.events.Event;
	
	import manager.BaseManager;
	
	import xinyou.jh.net.heartLaw.HeartLawReceiver;
	import xinyou.jh.net.heartLaw.HeartLawSender;
	import xinyou.jh.net.heartLaw.HeartLawStruct;
	import xinyou.jh.net.login.LoginReceiver;
	import xinyou.jh.net.login.LoginSender;
	import xinyou.jh.net.login.LoginStruct;
	import xinyou.jh.net.npcFell.NpcFeelReceiver;
	import xinyou.jh.net.npcFell.NpcFeelSender;
	import xinyou.jh.net.npcFell.NpcFeelStruct;
	import xinyou.jh.net.scene.SceneReceiver;
	import xinyou.jh.net.scene.SceneSender;
	import xinyou.jh.net.scene.SceneStruct;
	import xinyou.jh.net.server.ServerReceiver;
	import xinyou.jh.net.server.ServerStruct;
	import xinyou.jh.net.title.TitleReceiver;
	import xinyou.jh.net.title.TitleSender;
	import xinyou.jh.net.title.TitleStruct;
	
	public class SocketManager extends BaseManager
	{
		public var loginSocket:JHSocketConnection = new JHSocketConnection();
		public var mainSocket:JHSocketConnection = new JHSocketConnection();
		
		/** 登陆相关 **/
		public var loginStruct:LoginStruct = new LoginStruct();
		public var loginSender:LoginSender = new LoginSender(loginSocket);
		public var loginReceiver:LoginReceiver = new LoginReceiver(loginSocket);
		
		/** 场景相关 **/
		public var sceneSender:SceneSender = new SceneSender(mainSocket);
		public var sceneReceiver:SceneReceiver = new SceneReceiver(mainSocket);
		public var sceneStruct:SceneStruct = new SceneStruct();
		/** 服务器相关 **/
		public var serverReceiver:ServerReceiver = new ServerReceiver(mainSocket);
		public var serverStruct:ServerStruct = new ServerStruct();
		
		/** 心法相关 **/
		public var heartLawSender:HeartLawSender = new HeartLawSender(mainSocket);
		public var heartLawReceiver:HeartLawReceiver = new HeartLawReceiver(mainSocket);
		public var heartLawStruct:HeartLawStruct = new HeartLawStruct();
		
		/** npc好感相关 **/
		public var npcFeelSender:NpcFeelSender = new NpcFeelSender(mainSocket);
		public var npcFeelReceiver:NpcFeelReceiver = new NpcFeelReceiver(mainSocket);
		public var npcFeelStruct:NpcFeelStruct = new NpcFeelStruct();
		
		/** 称号相关 **/
		public var titleSender:TitleSender=new TitleSender(mainSocket);
		public var titleReceiver:TitleReceiver=new TitleReceiver(mainSocket);
		public var titleStruct:TitleStruct = new TitleStruct();
		public function SocketManager()
		{
			super();
			loginSocket.addEventListener(Event.CLOSE,loginSocketClose);
		}
		public static function getInstance():SocketManager
		{
			return SocketManager(BaseManager.getInstance("xinyou.jh.net::SocketManager"));
		}
		/**
		 * 登陆服务器断开的时候从内存卸载相关链接 
		 * @param event
		 * 
		 */		
		private function loginSocketClose(event:Event):void
		{
			loginSocket.removeEventListener(Event.CLOSE,loginSocketClose);
			loginSocket.dispose();
			loginSocket = null;
			loginReceiver.dispose();
			loginReceiver = null;
			loginSender.dispose();
			loginSender = null;
			loginStruct = null;
		}
	}
}